package io.kiki.stack.http.feign.SpringMvcContract.loadbalancer;

import org.springframework.boot.autoconfigure.condition.AnyNestedCondition;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.client.loadbalancer.LoadBalancedRetryFactory;
import org.springframework.retry.support.RetryTemplate;

/**
 * A condition that verifies that {@link RetryTemplate} is on the classpath, a
 * {@link LoadBalancedRetryFactory} bean is present and
 * <code>spring.cloud.loadbalancer.retry.enabled</code> is not set to <code>false</code>.
 */
public class OnRetryNotEnabledCondition extends AnyNestedCondition {

    public OnRetryNotEnabledCondition() {
        super(ConfigurationPhase.REGISTER_BEAN);
    }

    @ConditionalOnMissingClass("org.springframework.retry.support.RetryTemplate")
    static class OnNoRetryTemplateCondition {

    }

    @ConditionalOnMissingBean(LoadBalancedRetryFactory.class)
    static class OnRetryFactoryCondition {

    }

    @ConditionalOnProperty(value = "spring.cloud.loadbalancer.retry.enabled", havingValue = "false")
    static class OnLoadBalancerRetryEnabledCondition {

    }

}
